<?php
/*
 * @Descripttion: 
 * @Author: dedeye
 * @Date: 2020-02-25 20:12:50
 * @LastEditors: dedeye
 * @LastEditTime: 2020-02-27 11:56:24
 */

use think\migration\Migrator;
use think\migration\db\Column;

class Admin extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('admin', [
            'comment' => '管理员认证信息'
        ])->setCollation('utf8mb4_general_ci');
        $table->addColumn('username', 'string', [
            'limit'   => 15,
            'default' => '',
            'comment' => '用户名'
        ])->addColumn('nickname', 'string', [
            'limit'   => 32,
            'default' => '',
            'comment' => '用户昵称'
        ])->addColumn('password', 'char', [
            'limit'   => 32,
            'default' => '',
            'comment' => '用户密码'
        ])->addColumn('salt', 'integer', [
            'limit'   => 6,
            'default' => 0,
            'comment' => '盐值'
        ])->addColumn('status', 'boolean', [
            'limit'   => 1,
            'default' => 1,
            'comment' => '账号状态 0封号 1正常'
        ])->addColumn('create_ip', 'char', [
            'limit'   => 20,
            'default' => '',
            'comment' => '注册IP'
        ])->addColumn('create_time', 'integer', [
            'limit'   => 11,
            'default' => 0,
            'comment' => '注册时间'
        ])->addColumn('update_time', 'integer', [
            'limit'   => 11,
            'default' => 0,
            'comment' => '更新时间'
        ])->addIndex(['username'], ['unique' => true])->create();
    }
}
